using System;
using System.Collections.Generic;
using System.Linq;
using System.Web;
using System.Runtime.Serialization;
using DIS_DAL_WS.Models;

namespace DIS_DAL_WS.DTO
{
    [DataContract]
	public class WeeklyReportDTO
	{
        [DataMember]
		public int ID { get; set; }
        [DataMember]
		public int IDChemistWareHouse { get; set; }
        [DataMember]
		public DateTime StartDate { get; set; }
        [DataMember]
		public DateTime EndDate { get; set; }
        [DataMember]
        public string Note { get; set; }
        [DataMember]
        public ChemistWareHouseDTO ChemistWareHouse { get; set; }

        public static WeeklyReportDTO Translate(WeeklyReport Entity)
        {
            if (Entity != null)
            {
                var dto = new WeeklyReportDTO
                {
                    ID = Entity.ID,
                    StartDate = Entity.StartDate.Value,
                    EndDate = Entity.EndDate.Value,
                    Note = Entity.Note,
                    ChemistWareHouse = ChemistWareHouseDTO.TranslateBase(Entity.ChemistWareHouse)
                };
                if (Entity.IDChemistWareHouse != null)
                {
                    dto.IDChemistWareHouse = Entity.IDChemistWareHouse.Value;
                }
                else
                {
                    dto.IDChemistWareHouse = -1;
                }
                return dto;
            }
            return null;
        }

        public static WeeklyReport Reverse(WeeklyReportDTO obj)
        {
            var entity = new WeeklyReport
            {
                ID = obj.ID,
                StartDate = obj.StartDate,
                EndDate = obj.EndDate,
                Note = obj.Note
            };
            if (obj.IDChemistWareHouse != -1)
            {
                entity.IDChemistWareHouse = obj.IDChemistWareHouse;
            }
            return entity;
        }

        public void UpdateEntity(ref WeeklyReport entity)
        {
            entity.StartDate = StartDate;
            entity.EndDate = EndDate;
            entity.Note = Note;
            if (IDChemistWareHouse != -1)
            {
                entity.IDChemistWareHouse = IDChemistWareHouse;
            }
        }
	}
}